home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / DirectInput / ActionMapper / diutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  2.3 KB  |  72 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DIUtil.h
  3. //
  4. // Desc: DirectInput support using action mapping
  5. //
  6. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DIUTIL_H
  9. #define DIUTIL_H
  10.  
  11. #ifndef DIRECTINPUT_VERSION
  12. #define DIRECTINPUT_VERSION 0x0800
  13. #endif
  14.  
  15. #include <dinput.h>
  16.  
  17.  
  18.  
  19. #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
  20. #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
  21. #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
  22.  
  23.  
  24. //-----------------------------------------------------------------------------
  25. // Name: class CInputDeviceManager
  26. // Desc: Input device manager using DX8 action mapping
  27. //-----------------------------------------------------------------------------
  28. class CInputDeviceManager
  29. {
  30. public:
  31.     struct DeviceInfo
  32.     {
  33.         LPDIRECTINPUTDEVICE8 pdidDevice;
  34.         LPVOID               pParam;
  35.     };
  36.  
  37.     typedef HRESULT (CALLBACK *LPDIMANAGERCALLBACK)(CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi, LPVOID);
  38.  
  39. private:
  40.     BOOL                    m_bCleanupCOM;
  41.     HWND                    m_hWnd;
  42.     TCHAR*                  m_strUserName;
  43.  
  44.     LPDIRECTINPUT8          m_pDI;
  45.     DeviceInfo*             m_pDevices;
  46.     DWORD                   m_dwMaxDevices;
  47.     DWORD                   m_dwNumDevices;
  48.     DIACTIONFORMAT          m_diaf;
  49.  
  50.     LPDIMANAGERCALLBACK  m_AddDeviceCallback;
  51.     LPVOID               m_AddDeviceCallbackParam;
  52.  
  53. public:
  54.     // Device control
  55.     HRESULT AddDevice( const DIDEVICEINSTANCE* pdidi, LPDIRECTINPUTDEVICE8 pdidDevice );
  56.     HRESULT GetDevices( DeviceInfo** ppDeviceInfo, DWORD* pdwNumDevices );
  57.     HRESULT ConfigureDevices( HWND hWnd, IUnknown* pSurface, VOID* pCallback, DWORD dwFlags, LPVOID pvCBParam );
  58.     VOID UnacquireDevices();
  59.     VOID SetFocus( HWND hWnd );
  60.  
  61.     // Construction
  62.     HRESULT SetActionFormat( DIACTIONFORMAT& diaf, BOOL bReenumerate );
  63.     HRESULT Create( HWND hWnd, TCHAR* strUserName, DIACTIONFORMAT& diaf, LPDIMANAGERCALLBACK AddDeviceCallback, LPVOID pCallbackParam );
  64.  
  65.     CInputDeviceManager();
  66.     ~CInputDeviceManager();
  67. };
  68.  
  69. #endif
  70.  
  71.  
  72.